<?php
    $check = 0;
    if(trim($_POST['cc_code'])!=''){
        $cc_code = addslashes(trim($_POST['cc_code']));
        $cc_id = addslashes($_POST['cc_id']);
        
        $result = $db->Execute("SELECT cc_id FROM customer_company WHERE cc_code='$cc_code' AND cc_id!=$cc_id");
        if($result->RowCount()>0){
            $msg = 'Company Code นี้ถูกใช้ไปแล้ว';
        }else{
            $cc_name = addslashes($_POST['cc_name']);
            $cc_address1 = addslashes($_POST['cc_address1']);
            $cc_address2 = addslashes($_POST['cc_address2']);
            $cc_website = addslashes($_POST['cc_website']);
            $cc_budget = addslashes($_POST['cc_budget']);
            $cc_remark = addslashes($_POST['cc_remark']);
            
            $sql = "UPDATE customer_company SET
            cc_code='$cc_code' ,
            cc_name='$cc_name' ,
            cc_address1='$cc_address1' ,
            cc_address2='$cc_address2' ,
            cc_website='$cc_website' ,
            cc_budget='$cc_budget' ,
            cc_remark='$cc_remark' WHERE cc_id=$cc_id";
            $result = $db->Execute($sql);
            
            if($result){
                $msg = 'บันทึกข้อมูลเรียบร้อยแล้ว';
                $check = 1;
            }else{
                $msg = 'ไม่สามารถบันทึกข้อมูลได้';
            }
        }
    }else{
        $msg = 'กรุณากรอก Company Code';
    }
?>

<?php
    include('header.php');
    include('submenu.php');
?>
<div class="grid_18" id="contents">
    <div id="query_result">
    <?php
        //echo $msg , ' <img src="images/ajax-loader.gif" />';
        //redirect('?m=customer&s=company',3);
        alert($msg);
    ?>
    </div>
</div><!-- end .grid_18 -->
<div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>
<script>
    $(document).ready(function(){
        if(<?php echo $check; ?>==0){
            $('#ajax_loader',window.parent.document).css('display','none');
        }else{
            top.window.location = '?m=customer&s=company';
        }
    });
</script>